package se.vgregion.icc;

import java.util.HashMap;
import java.util.Map;

import se.riv.itintegration.dependencies.v1.AbstractDependency;
import se.vgregion.icc.handlers.PingHandler;

/***
 * Registry for PingHandlers, holder of PingHandler instances.
 * 
 * @author ricra2 & andan40
 * @see {@link se.vgregion.icc.handlers.PingHandler}
 */
@SuppressWarnings("rawtypes")
public final class PingHandlerRegistry {

    private Map<Class, PingHandler> pingHandlers;

    private PingHandlerRegistry() {
        pingHandlers = new HashMap<Class, PingHandler>();
    }

    /***
     * Gets an PingHandler implementation based on the dependency to ping. 
     * 
     * @param dependency the dependency you want to handle
     * @return PingHandler to handle the dependency
     */
    public PingHandler getPingHandler(AbstractDependency dependency) {
        return pingHandlers.get(dependency.getClass());
    }

    /***
     * Register the PingHandler and the class it can handle.
     * 
     * @param classToHandle the class the implementation can handle, this will become the HashMap key.
     * @param implementation the implemented class you want to add
     */
    public void addPingHandlerImplementation(Class classToHandle, PingHandler implementation) {
        pingHandlers.put(classToHandle, implementation);
    }
}
